package ewelinkapi

import (
	"os"

	"gitee.com/libs_2/ewelinkapi/model"
)

// 连接断开
type OnConnectionClose func(interrupt <-chan os.Signal)

// 设备在线状态变化事件回调函数
type OnDeviceOnlineStateChange func(msg model.NotifyDeviceOnline)

// 4通道开关设备状态更新回调函数
type OnDeviceUpdateState func(msg model.NotifyOutlet4Update)

// 注册设备在线状态变化事件回调函数
func (c *Client) UseDeviceOnlineStateChange(fns ...OnDeviceOnlineStateChange) {
	c.onDeviceOnlineChanges = append(c.onDeviceOnlineChanges, fns...)
}

// 注册4通道开关设备状态更新回调函数
func (c *Client) UseDeviceUpdateState(fns ...OnDeviceUpdateState) {
	c.onDeviceOutlet4UpdateState = append(c.onDeviceOutlet4UpdateState, fns...)
}

// 注册连接断开回调函数
func (c *Client) UseOnConnectionClose(fn OnConnectionClose) {
	c.onConnectionClose = fn
}

func (c *Client) OnDeviceOnlineChange(msg model.NotifyDeviceOnline) {
	for _, fn := range c.onDeviceOnlineChanges {
		fn(msg)
	}
}

func (c *Client) OnDeviceOutlet4UpdateState(msg model.NotifyOutlet4Update) {
	for _, fn := range c.onDeviceOutlet4UpdateState {
		fn(msg)
	}
}
